# $Header: /mount/cvs-repository/Aligner/lib/perl/packs/Desc.pm,v 1.1 2007/10/08 09:26:03 schweitz Exp $
package Desc;

=head1 NAME

Desc --- Ordered Key-Description pair allowing recursive structure

=cut

sub new {
    my $class = shift;
    my $this = {
	'key' => [],
	'desc' => {}
    };
    bless $this, $class;
}

sub DESTROY ($) {
    my $this = shift;
}

sub Add ($$) {
    my $this = shift;
    my ($key, $desc) = @_;

    push(@{$this->{key}}, $key);
    ${$this->{desc}}{$key} = $desc;
}

sub GetKey {
    my $this = shift;
    my $idx = shift;

    ${$this->{key}}[$idx];
}

sub GetDesc ($) {
    my $this = shift;
    ${$this->{desc}}{$_[0]};
}

sub GetKeys {
    my $this = shift;
    @{$this->{key}};
}

sub GetNKeys {
    my $this = shift;
    $#{$this->{key}};
}

sub Shift {
    my $this = shift;
    my $k = shift @{$this->{key}};
    my $d = ${$this->{desc}}{$k};
    undef ${$this->{desc}}{$k};
    ($k, $d);
}
sub Dump {
    my $this = shift;
    print "KEYS: " . join(',', @{$this->{key}}) . "\n";
}
1;
